package com.ruoyi.womp.service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.utils.security.PermissionUtils;

@Service
public class WompServiceUtil {

	@Autowired
	ISqlQueryService sqlQueryService;

	public List<Map<String, Object>> getDetpUserList() {
		String userDeptId = PermissionUtils.getPrincipalProperty("deptId").toString();
		List<Map<String, Object>> userList = new ArrayList<Map<String, Object>>();

		String sql = " select login_name,user_name from sys_user where login_name!='admin' and dept_id=" + userDeptId;
		List<Map<String, Object>> list = sqlQueryService.queryMapList(sql);

		HashSet h = new HashSet(list);
		userList.clear();
		userList.addAll(h);

		return userList;
	}

	public List<Map<String, Object>> getElementSystemHandelOptions(String elementCode) {

		String sql = " select ifnull(handling_opinions,'') handling_opinions,file_sources from womp_handling_opinions "
				+ " where code='" + elementCode + "' limit 1 ";
		return sqlQueryService.queryMapList(sql);
	}

	public List<Map<String, Object>> getWaElementNum(String waCode) {
		String sql = " SELECT we.name,element_code,count(element_code) elementNum FROM womp_weighing_apparatus_element wwae "
				+ " inner join womp_element we on wwae.element_code=we.code and wwae.wa_code='" + waCode
				+ "' group by we.name,element_code ";

		return sqlQueryService.queryMapList(sql);
	}

}